<template>
	<div>
    <el-card>
      <template #header>
        <span>活动参与情况</span>
      </template>
      <el-table :data="tableData" border>
        <el-table-column prop="name" label="姓名" align="center">
        </el-table-column>
        <el-table-column prop="age" label="年龄" align="center">
        </el-table-column>
        <el-table-column prop="sex" label="性别" align="center">
        </el-table-column>
        <el-table-column prop="phone" label="手机号" align="center">
        </el-table-column>
        <el-table-column prop="join_time" label="入党时间" align="center">
        </el-table-column>
        <el-table-column prop="work_unit" label="工作单位" align="center">
        </el-table-column>
        <el-table-column prop="position" label="职位" align="center">
        </el-table-column>
        <el-table-column prop="work_status" label="工作状态" align="center">
        </el-table-column>
        <el-table-column prop="qiandaoStatus" label="签到情况" align="center">
			<template slot-scope="scope">
				<span v-if="scope.row.qiandaoStatus === '0'">未签到</span>
				<span v-if="scope.row.qiandaoStatus === '1'">已签到</span>
			</template>
        </el-table-column>
        <el-table-column prop="fankui" label="反馈评价" align="center">
        </el-table-column>
      </el-table>
    </el-card>
	</div>
</template>
<script>
	import router from '../../router';
	export default {
		mounted() {
			// console.log(router.currentRoute.params)
			// 接收路由传参----活动ID
			this.SelectAllMethod(router.currentRoute.params.activity_id);
		},
		data() {
			return {
				tableData:[]   ,// 报名名单
			};
		},
		methods: {
			// 查询全部参与人员信息
			async SelectAllMethod(_id){
				this.tableData = [];
				// console.log(this._id);
				let res = await this.$axios({
					url:'/api/participants',
					method:'post',
					data:{_id}
				});
				console.log(res);
				if(res.data.status===1){
					// 查询成功
					for(let i=0;i<res.data.data.length;i++){
						const temp = JSON.parse(res.data.data[i]);
						temp.age = this.AgeMethod(temp.age);
						this.tableData.push(temp);
					}
				}else{
					// 查询失败
				}
			},
			// 出生日期转年龄
			AgeMethod(param) {
				const birthDate = new Date(param);
				// 获取当前日期
				const today = new Date();
				// 计算年龄
				let age = today.getFullYear() - birthDate.getFullYear();
				// 但是，如果今天还没有到生日那天，我们需要从年龄中减去1
				const m = today.getMonth() - birthDate.getMonth();
				if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
					age--;
				}
				return age;
			},
		},
	};
</script>
<style scoped>
	.hao {
		height: 40px;
		line-height: 40px;
		text-align: center;
	}

	.a {
		margin-bottom: 30px;
	}
</style>